#pragma once

#include <d3dx9.h>


enum Direction
{
   DIR_FORWARD = 1,
   DIR_BACKWARD = 2,
   DIR_LEFT = 4,
   DIR_RIGHT = 8,
   DIR_UP = 16,
   DIR_DOWN = 32,
   DIR_FORCE_32BIT = 0x7FFFFFFF
};

class IMovable;

class PhysicalObject
{
private:
   IMovable& m_movable;

   float m_acceleration;
   float m_maxHorizontalSpeed;
   float m_maxVerticalSpeed;
   D3DXVECTOR3 m_gravity;
   float m_friction;

   D3DXVECTOR3 m_velocity;

public:
   PhysicalObject(IMovable& movable);

   void move(DWORD direction, float timeElapsed);

   void applyForce(const D3DXVECTOR3& forceVec);

   void rotate(DWORD direction, float timeElapsed);

   void update(float timeElapsed);

   void setAcceleration(float val) {m_acceleration = val;}
   void setMaxHorizontalSpeed(float val) {m_maxHorizontalSpeed = val;}
   void setMaxVerticalSpeed(float val) {m_maxVerticalSpeed = val;}
   void setWeight(float val) {m_gravity.y = -val * 10.0f;}
   void setFriction(float val) {m_friction = val;}

   IMovable& getMovable() { return m_movable; }

   D3DXVECTOR3 getMovementForce();

private:
   void calculatePhysics(float timeElapsed);
};
